package com.easy.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easy.common.bean.SeckillProduct;
import com.easy.common.service.SeckillProductService;
import com.easy.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/seckillProduct")
public class SeckillProductController {

    @Autowired
    private SeckillProductService seckillProductService;

    @GetMapping("{id}")
    public Result getOne(@PathVariable("id") Integer id){
        SeckillProduct seckillProduct = seckillProductService.getById(id);
        return Result.success(seckillProduct);
    }

    @GetMapping("page")
    public Result page( SeckillProduct seckillProduct, Page page){
        QueryWrapper<SeckillProduct> queryWrapper = new QueryWrapper<>(seckillProduct);
        return Result.success(seckillProductService.page(page, queryWrapper));
    }
    @PostMapping
    public Result save(@RequestBody SeckillProduct seckillProduct){
        return Result.success(seckillProductService.save(seckillProduct));
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        return Result.success(seckillProductService.removeById(id));
    }

    @PutMapping
    public Result update(@RequestBody SeckillProduct seckillProduct){
        return Result.success(seckillProductService.updateById(seckillProduct));
    }

    @GetMapping("all")
    public Result findAll(){
        return Result.success(seckillProductService.list());
    }

}
